<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>租赁物资料信息</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
	<div class="fieldset1 tabel_col tabel_col_s clearFix">
		<div class="sqPanel">
			<div class="sqPanel_head inL">
			    <span>租赁物资料</span>
			     <c:if test="${ pianflag != '101'}">
			    <span class="btns"><span class="sq-button sq-button-round" onclick="downloadPrjPrdDtlFileByUrl();">打包下载</span></span>
			    </c:if>
			</div>
            <div class="sqPanel_body">
			    <div id="prjPrdDtlFileInfoCfgGrid" class="sq-grid"></div>
            </div>
		</div>
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <span>发票管理</span>
                <c:if test="${ pianflag != '101'}">
                <span class="btns"><span class="sq-button sq-button-round" onclick="downloadPrjPrdInvoiceFileByUrl();">打包下载</span></span>
                </c:if>
            </div>
            <div class="sqPanel_body">
                <div id="invoiceGrid" class="sq-grid"></div>
            </div>
        </div>
    </div>
</div>
<!-- 资料上传DIV -->
<div id="prjPrdDtl_file_div" style="display:none">
    <form id="prjPrdDtl_file_formSet">
        <div class="fieldset1 tabel_col noBorder clearFix">
            <div class="fieldBox col_100">
                <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true" >
                    <jsp:param name="fileNum" value="1"/>
                    <jsp:param name="filePath" value="capital/capPayInfo"/>
                </jsp:include>
            </div>
        </div>
        <input type="text" style="display: none;" id="cfgCd" name="cfgCd">
        <input type="text" style="display: none;" id="cfgDtlCd" name="cfgDtlCd">
        <input type="text" style="display: none;" id="orgCd" name="orgCd">
        <input type="text" style="display: none;" id="prjPrdDtlId" name="prjPrdDtlId" value="${prjPrdDtlId}">
        <input type="text" style="display: none;" id="prjPrdId" name="prjPrdId" value="${prjPrdId}">
        <input type="text" style="display: none;" id="prjId" name="prjPrdId" value="${prjId}">
    </form>
</div>
<script type="text/javascript">
    var prjPrdDtlFileInfoCfgGrid = null;
    var invoiceGrid = null;
    var ctrlKey='${ctrlKey}';
    $(function () {
        prjPrdDtlFileInfoCfgGrid = $("#prjPrdDtlFileInfoCfgGrid").ligerGrid({
            <%--url: '<%=path%>/project/prjFileInfo/initFileListByDataId.do?cstMgrOrgCd=${cstMgrOrgCd}&dataId=${prjPrdDtlId}',--%>
            url: '<%=path%>/project/prjFileCfgInfo/initPrjPrdDtlFileInfoList.do?isShowSts=0&cstMgrOrgCd=${cstMgrOrgCd}&prjPrdDtlId=${prjPrdDtlId}&prjTypCd=${prjTypCd}&prjId=${prjId}&prjPrdId=${prjPrdId}',
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            //return '<a target="_blank" name="showimg" href="'+rowdata.filePath+'">'+rowdata.fileNm+'</a>';
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
           rownumbers:true,  //显示序号
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            rowAttrRender: function (rowdata,rowid)
            {
               if ( '${pianflag}' == '101' && rowdata.datNm=='租赁物其他资料')
               {
              	   //alert("55");
                     //return "style='background:#48D9AE;'";
                   var manager = $("#prjPrdDtlFileInfoCfgGrid").ligerGetGridManager();
						manager.deleteRow(rowdata);
  
              	   return "style='display:none;'";
                }
              return "";
            },
            onAfterShowData: function (){
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('datNm');
            }
        });

        invoiceGrid = $("#invoiceGrid").ligerGrid({
            url: '<%=path%>/project/prjFileCfgInfo/initInvoiceList.do?isShowSts=1&cstMgrOrgCd=${cstMgrOrgCd}&prjPrdDtlId=${prjPrdDtlId}&prjTypCd=${prjTypCd}&prjId=${prjId}&prjPrdId=${prjPrdId}&paySchNo=${paySchNo}',
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            //return '<a target="_blank" name="showimg" href="'+rowdata.filePath+'">'+rowdata.fileNm+'</a>';
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '状态', name: 'audStsCdNm', minWidth: 100, enabledSort: false}

            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            //显示序号
            rownumbers:true,
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function (){
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('datNm');
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('uploadNm');
            }
        });

        $("#pageloading").hide();
    });
    
    function downloadPrjPrdDtlFileByUrl() {
        var data = prjPrdDtlFileInfoCfgGrid.getData();
     	//var files = [];
        var ids = [];
		for (var i = 0; i < data.length; i++) {
		    var map = {};
		    /* if(data[i].filePath){
			    map.name = data[i].fileNm;
			    map.path = data[i].filePath.substring(data[i].filePath.indexOf("attachments"));
			    files.push(map);
		    } */
		    ids.push(data[i].fileId);
		}
		var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do?';
    	var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }

    function downloadPrjPrdInvoiceFileByUrl() {
        var data = invoiceGrid.getData();
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            var map = {};
            if(StringUtils.isNotEmpty(data[i].fileId)){
                ids.push(data[i].fileId);
            }
        }
        var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do?';
        var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }

    $(function () {
        $(document).on('click', 'a[name=showimg]', function(){
            event.preventDefault();
            var href = $(this).attr('href');
            reg = new RegExp('^.*\.(?:png|jpg|bmp|gif|jpeg|PNG|JPG|BMP|GIF|JPEG)$');
            if (reg.test(href)) {
                SQ.imgPreview(href);
            }else{
                window.open(href);
            }
        });
    });
    
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    var reloadChildGridId = null;
  	//上传租赁物文件
    function upFileForPrjPrdDtl(event,_cfgCd,_cfgDtlCd,_orgCd){
    	//获取子GridID
    	event.stopPropagation();
        reloadChildGridId = $(event.target).parents('.sq-grid').attr('ligeruiid');
        
        $("#cfgCd").val(_cfgCd);
        $("#cfgDtlCd").val(_cfgDtlCd);
        $("#orgCd").val(_orgCd);
        $.ligerDialog.SQopen({
            width: 400,
            height:100,
            title : '资料上传',
            target: $("#prjPrdDtl_file_div"),
        });
    }
    //上传租赁物文件回调方法
    function uploadCallback(_data){
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileParams':JSON.stringify(_data),'prjPrdDtlId':$("#prjPrdDtlId").val(),'cfgCd':$("#cfgCd").val(),'cfgDtlCd':$("#cfgDtlCd").val(),'orgCd':$("#orgCd").val()},
            url: '<%=path%>/project/prjFileInfo/uploadPrjPrdDtlFile.do',
            success: function (msg) {
                if (msg.success == 1) {
                    parent.$('li[tabid="mateTab"] a').text('租赁物资料('+msg.data+')');
                    /* if(prjPrdDtlFileInfoGrid){
	                    prjPrdDtlFileInfoGrid.reload();
                    } */
                    if(reloadChildGridId) liger.get(reloadChildGridId).reload();
                }else{
                    $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                }
                $.ligerDialog.hide();
            }
        });
    }

    //删除文件
    function delFile(event,_fileId){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId},
            url: '<%=path%>/project/prjFileInfo/removeFile.do',
            beforeSend: function () {
               wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    parent.$('li[tabid="mateTab"] a').text('租赁物资料('+msg.data+')');
                    /* if(prjPrdDtlFileInfoGrid){
                    	prjPrdDtlFileInfoGrid.reload();
                    } */
                    event.stopPropagation();
                    var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                    liger.get(gridID).reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //修改资料的验证状态
    function modifyAudStsCd(event,_fileId,_audStsCd){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId,'audStsCd':_audStsCd},
            url: '<%=path%>/project/prjFileInfo/modifyFileAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    //$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    /* if(prjPrdDtlFileInfoGrid){
                    	prjPrdDtlFileInfoGrid.reload();
                    } */
                    event.stopPropagation();
                    var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                    liger.get(gridID).reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //下载
    function downFile(_url){
        //window.location.href=_url;
        window.open(_url);
    }
    function uploadFileByUrl(_url,_name){
		if(SQ.regs.img.test(_name)){
			//SQ.imgPreview(_url);
			//SQ.imgPreview(_url, true);
	       window.__ImgSrc = _url;
	       window.__ImgTit = _name;
	       window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
		}else if(SQ.regs.img.test(_url)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
	        window.open(_url);
		}
    }
    
    var prjPrdDtlFileInfoGrid = null;//租赁物资料配置明细下附件Grid
    //租赁物资料配置明细下附件列表
    function showDetail_prjPrdDtlFileInfoCfgGrid(row, detailPanel, callback){
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);

        prjPrdDtlFileInfoGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/project/prjFileInfo/initPrjPrdDtlFileInfoList.do?prjPrdDtlId=${prjPrdDtlId}&cfgDtlCd='+row.cfgDtlCd,
            method: 'get',
            columns: [
				{display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,rowindex,value){
				        if(value){
				            //return '<a target="_blank" name="showimg" href="'+rowdata.filePath+'">'+rowdata.fileNm+'</a>';
				        	var h;
				            h='<a href="javascript:uploadFileByUrl(';
			                h+="'"+rowdata.filePath+"'";
			                h+=",'"+rowdata.fileNm+"'";
			                h+=')">'+rowdata.fileNm+'</a>'
			                return h;
				        }
				    }
				},
				{display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
				{display: '状态', name: 'audStsCdNm', width: 100, align: 'left', enabledSort: false},
				{display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,rowindex,value){
				        var h='';
			            if(ctrlKey==1){
			                //h+='<a class="sq-button-hasicon" style="cursor:pointer;" onclick="downFile(\''+rowdata.filePath+'\');"><i class="sqBtnIco_8"></i>下载</a>';
			                if(rowdata.audStsCd!=1) {
			                    h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
			                }
			            }else if(ctrlKey==2){
			                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId +',1);"><i class="sqBtnIco_15"></i>验证通过</a>';
			                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',2);"><i class="sqBtnIco_14"></i>验证不通过</a>';
			            }
				        return h;
				    }
				},
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }
    
</script>

</body>
</html>
